package com.bdqn.servlet.index;

import com.bdqn.service.SysUserService;
import com.bdqn.service.impl.SysUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * LogoutServlet
 *
 * @author LILIBO
 * @since 2024/7/3
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {

    /**
     * 引入业务逻辑层
     */
    private final SysUserService sysUserService = new SysUserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 清空Session
        request.getSession().removeAttribute("userSession");
        request.getSession().invalidate();
        // 重定向到登录页
        response.sendRedirect("login");
    }

}
